Skip to content

feat(c/db2): add initial connection-only Db2 driver#4286

Open
nishantchandraa wants to merge 1 commit intoapache:mainfrom
nishantchandraa:feature/db2-driver-connection-only-clean
Open

feat(c/db2): add initial connection-only Db2 driver#4286
nishantchandraa wants to merge 1 commit intoapache:mainfrom
nishantchandraa:feature/db2-driver-connection-only-clean

Conversation

@nishantchandraa
Copy link
Copy Markdown

Summary

This PR introduces an initial C/C++ ADBC driver for IBM Db2, intentionally scoped to connection management only so maintainers can review a small, focused baseline.

Included in this PR

  • New Db2 driver skeleton integrated into C/C++ build and packaging wiring
    • CMake option and subdirectory integration
    • Meson integration
    • Driver config and pkg-config metadata
  • DB2 database/connection lifecycle implementation
    • Database init/release (SQLHENV management)
    • Connection init/release (SQLHDBC allocation, connect, disconnect)
    • Default autocommit behavior on connection init
  • Connection option handling
    • uri support
    • per-field options: database, hostname, port, uid, pwd
    • standard username / password synonyms
    • explicit precedence: uri overrides conflicting per-field options
  • Connection-level validation/error behavior
    • malformed port rejected (1-65535 required)
    • empty UID/PWD rejected
    • SQLSTATE-to-ADBC status mapping for connection/auth failures
  • Minimal connection-focused tests and docs
    • lifecycle and concurrent-connection flow
    • missing/unknown option handling
    • invalid credentials handling
    • unreachable endpoint mapping
    • option precedence and validation behavior
    • DB2 driver docs + index inclusion

Explicitly out of scope

  • Statement execution
  • Result fetching/cursor handling
  • Metadata APIs (GetInfo, GetObjects, schemas/catalog)
  • Transaction APIs beyond default connection behavior
  • Bulk ingest and advanced type mapping
  • Performance optimizations

Validation

Tested against a live Db2 instance on localhost:50000:

  • adbc-driver-db2-test: 15/15 passed
  • ctest -L driver-db2: pass

Coverage includes:

  • database/connection init+release
  • autocommit default and concurrent connection flow
  • invalid credentials
  • malformed port
  • empty UID/PWD
  • unreachable host/port error mapping
  • uri precedence over per-field options

Notes for reviewers

This PR is intentionally narrow to establish a clean, reviewable baseline for DB2 support in ADBC. Follow-up PRs will add statement execution, metadata, transaction functionality, and broader feature parity incrementally.

Introduce the IBM DB2 C/C++ driver skeleton with connection lifecycle support, option parsing, and connection-level error handling to establish a small, reviewable baseline. Add focused connection-flow tests and minimal build/docs wiring while deferring execution and metadata APIs to follow-up work.
@nishantchandraa nishantchandraa marked this pull request as draft April 30, 2026 10:33
@nishantchandraa nishantchandraa marked this pull request as ready for review April 30, 2026 17:59
@nishantchandraa nishantchandraa marked this pull request as draft May 1, 2026 05:35
@nishantchandraa nishantchandraa marked this pull request as ready for review May 1, 2026 05:39
@nishantchandraa
Copy link
Copy Markdown
Author

Hi @lidavidm @kou,

I’d really appreciate your feedback on this initial DB2 ADBC driver PR.

This change is intentionally scoped to connection management only, so we can align early on structure and approach before expanding further.

Specifically, I’d love feedback on:

Overall driver structure and integration with the existing ADBC C/C++ layout
Connection lifecycle implementation (database/connection init & release)
Option handling (URI + per-field options precedence)
Error/status mapping approach (SQLSTATE → ADBC)

If this direction looks good, I plan to follow up with smaller PRs for:

statement execution
result fetching / Arrow conversion

Please let me know if you’d prefer this to be split further or structured differently.

Thanks!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the first C/C++ ADBC driver skeleton for IBM Db2, scoped to connection management so the codebase can land a narrow baseline before execution and metadata support are added later. It extends the existing ADBC C/C++ driver set with build wiring, Db2-specific connection handling, and initial docs/tests.

Changes:

  • Adds a new c/driver/db2 driver with database/connection lifecycle, option parsing, and SQLSTATE-to-ADBC error mapping.
  • Wires the Db2 driver into CMake/CI/docs and adds package metadata/public headers.
  • Adds connection-focused tests covering lifecycle, validation, precedence, and selected failure modes.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
docs/source/index.rst Adds the Db2 driver page to the docs index.
docs/source/driver/db2.rst Introduces end-user Db2 driver documentation.
ci/scripts/cpp_test.sh Adds Db2 test label selection to C++ test script.
c/include/arrow-adbc/driver/db2.h Adds the public Db2 driver C header and options.
c/driver/db2/statement.h Adds the initial Db2 statement stub.
c/driver/db2/README.md Adds driver-local build/testing notes.
c/driver/db2/meson.build Adds Meson build metadata for the Db2 driver.
c/driver/db2/error.h Declares Db2 error helpers and SQLSTATE mapping.
c/driver/db2/error.cc Implements diagnostic extraction and status mapping.
c/driver/db2/db2.cc Exposes the driver entrypoints and ADBC trampolines.
c/driver/db2/db2_test.cc Adds Db2 connection and option tests.
c/driver/db2/db2_odbc.h Adds the shared Db2 CLI/ODBC include wrapper.
c/driver/db2/database.h Declares the Db2 database object and state.
c/driver/db2/database.cc Implements environment setup, options, and connection-string building.
c/driver/db2/connection.h Declares the Db2 connection object.
c/driver/db2/connection.cc Implements connect/disconnect and default autocommit setup.
c/driver/db2/CMakeLists.txt Adds CMake build/test/package wiring for the driver.
c/driver/db2/AdbcDriverDb2Config.cmake.in Adds CMake package config template for the driver.
c/driver/db2/adbc-driver-db2.pc.in Adds pkg-config metadata for the driver.
c/CMakeLists.txt Wires the Db2 driver into the top-level C build.
c/cmake_modules/DefineOptions.cmake Adds the top-level CMake build option for Db2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread c/driver/db2/meson.build
Comment on lines +18 to +20
db2_dep = meson.get_compiler('c').find_library('db2', required: true)

adbc_db2_driver_lib = library(
Comment thread c/driver/db2/meson.build
Comment on lines +18 to +19
db2_dep = meson.get_compiler('c').find_library('db2', required: true)

Comment thread c/CMakeLists.txt
adbc_install_python_package(snowflake)
endif()

if(ADBC_DRIVER_DB2)
Comment thread c/driver/db2/database.cc

Status Db2Database::ReleaseImpl() {
if (henv_ != SQL_NULL_HENV) {
SQLFreeHandle(SQL_HANDLE_ENV, henv_);
Comment on lines +29 to +36
// SQLDriverConnect mutates the input string; copy to a stable buffer.
const std::string& conn_str = database_->connection_string();
SQLCHAR out_str[1024];
SQLSMALLINT out_len = 0;
SQLRETURN rc = SQLDriverConnect(
hdbc_, /*WindowHandle=*/nullptr,
const_cast<SQLCHAR*>(reinterpret_cast<const SQLCHAR*>(conn_str.c_str())),
static_cast<SQLSMALLINT>(conn_str.size()), out_str, sizeof(out_str), &out_len,
Comment on lines +33 to +34
subsequent pull requests. Calling those entry points returns
``ADBC_STATUS_NOT_IMPLEMENTED``.
Comment thread c/driver/db2/db2_test.cc
Comment on lines +131 to +133
if (GetTestUri() == nullptr) {
GTEST_SKIP() << "ADBC_DB2_TEST_URI not set";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants